import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {HomeComponent} from './components/home/home.component';
import {ProductComponent} from './components/product/product.component';
import {Code404Component} from './components/code404/code404.component';
import {ProductDescComponent} from './components/product-desc/product-desc.component';
import {ShellerInfoComponent} from './components/sheller-info/sheller-info.component';
import {ChatComponent} from "./components/chat/chat.component";
import {LoginGuard} from "./gurad/login.guard";
import {UnsaveGuard} from "./gurad/unsave.guard";
import {ProductResolveGuard} from "./gurad/product-resolve.guard";
import {ProductDetailComponent} from "./components/product-detail/product-detail.component";

const routes: Routes = [
  {path: '', redirectTo: 'home', pathMatch: 'full'},
  {path: 'home', component: HomeComponent},
  /*当前的路由显示在哪个插座上 没有定义outlet的路由 绑定在主插座上*/
  /*<router-outlet name="aux"></router-outlet>*/
  {path: 'chat', component: ChatComponent, outlet: 'aux'},
  /*路径信息中携带参数 在ProductComponent中写子组件*/
  {
    path: 'product/:id', component: ProductComponent,
    /*可以指定多个守卫，但是每个只要一个守卫不符合条件，就不会访问组件*/
    /*canActivate: [LoginGuard],*/
    /*离开路由*/
    /*canDeactivate: [UnsaveGuard],*/
    /*传入参数的名称*/
    resolve: {
      product: ProductResolveGuard
    },
    children: [
      /*相对于product/:id*/
      {path: '', redirectTo: 'productDesc', pathMatch: 'full'},
      {path: 'productDesc', component: ProductDescComponent},
      {path: 'shellerInfo/:id', component: ShellerInfoComponent}
    ]
  },
  {path: 'product', component: ProductComponent},
  /*用来匹配页面不存在的情况404,放在最后，因为angular是根据路由代码的顺序执行*/
  {path: '**', component: Code404Component}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: [LoginGuard, UnsaveGuard, ProductResolveGuard]
})
export class AppRoutingModule {
}
